<template>
  <div class="container">
    <div class="page-header">
      <h1>{{title}}</h1>
    </div>
    <table class="table table-striped table-bordered table-hover">
      <thead>
        <tr>
          <th>编号</th>
          <th>名称</th>
          <th>价格</th>
        </tr>
      </thead>
      <tbody>
        <tr v-for="product in products" :key="product.id">
          <td>{{ product.id }}</td>
          <td>{{ product.title }}</td>
          <td>{{ product.price }}</td>
        </tr>
      </tbody>
    </table>
  </div>
</template>

<script>
import axios from "axios";
export default {
  name: "home",
  async asyncData() {
    const { data: products } = await axios.get(
      "http://localhost:3000/app/api/products.json"
    );
    return {
      products,
    };
  },
  data(){
    return {
      title:'商品'
    }
  }
};
</script>